<?php
namespace jy_security;
defined('BY_JYA') or exit('error');
/*
	防伪商品
*/
class goods extends \plugin{
	function add($goods){
		$goods=array_fields(array('title','price','image','content','url','type','goodsid','isweishop'),$goods);
		$setting=$this->plugin_setting('secury');
		if(!$setting['pre'] || !$setting['goods'] ||  !$setting['batch'] || !$setting['serial'] || !$setting['code'] || !$setting['garble']){
			exi('请先设置好-参数设置--防伪码前缀/批号位数/流水号位数/校验码位数/混淆码位数！','error');
		}
		do{
			$code=rand(pow(10,($setting['goods']-1)), pow(10,$setting['goods'])-1);
			$v=pdo_get('jy_security_goods',array('code'=>$code));
		}while($v);
		$goods['code']=$code;
		if(!$goods['type']){
			$goods['type']=2;
		}
		$goods['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_security_goods',$goods);
		$id=pdo_insertid();
		return $id;
		
	}
	function update($goods_id,$data){
		$goods=array_fields(array('title','price','image','content','url'),$data);
		pdo_update('jy_security_goods',$goods,array('id'=>$goods_id));
	}
}